package com.example.learnspring.controller;


import com.example.learnspring.entity.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class UploadController {

    @PostMapping("/upload")
    public Result upload(String name, MultipartFile file) throws IOException {
        String filename = file.getOriginalFilename();
        String path =  UUID.randomUUID().toString() + filename.substring(filename.lastIndexOf("."));
        file.transferTo(new File("D:/download/"+path));
        return Result.success();
    }

}
